clear all
set more off
global data 	"R:\SharedProjects\Shared2020-070\2016\extend_to_2020\JPE_Replication_dta"
global figures 	"R:\SharedProjects\Shared2020-070\2016\extend_to_2020\JPE_Replication_log"
global in 		"R:\SharedProjects\Shared2020-070\2016\input"

cap log close
log using $figures\H_file,replace t

cd $data


**************************************************************************************************************************************************************************************************************************************************************************************
*************************************************************************************************************************************************************************************************************************************************************************************
*************************************************************************************************************************************************************************************************************************************************************************************
cd $data
u sampleA.dta, clear

********************************************************************************************************************************************************************************************************************
global spec1 female
global spec2 female college racex2 experience ssi_only ssi_and_di married_appl widowed_appl age
global spec3 female college racex2 experience ssi_only ssi_and_di married_appl widowed_appl age yrd* bsx2 bsx3 bsx4 bsx5 bsx6 bsx7 bsx8 bsx9 bsx10
global spec4 female college racex2 experience ssi_only ssi_and_di married_appl widowed_appl age yrd* bsx2 bsx3 bsx4 bsx5 bsx6 bsx7 bsx8 bsx9 bsx10 ///
			 doctor* walkra_appl_1 dressa_appl_1 stoopa_appl_1 beda_appl_1 hosp_appl_1 bmi_appl longestoccx*
global spec5 female college racex2 experience ssi_only ssi_and_di married_appl widowed_appl age yrd* longestoccx*
********************************************************************************************************************************************************************************************************************
						 
lab var someworklim "Some work limitations"	
lab var nosuccess "No award, appl. round"
lab var nosuccess_cycle	"No award, appl. cycle"	
lab var cantwork_notemp_appl "Work disabled"		 

lab var yrd1 "Year=1991"
lab var yrd2 "Year=1992"
lab var yrd3 "Year=1993"
lab var yrd4 "Year=1994-95"
lab var yrd5 "Year=1996"
lab var yrd6 "Year=1997"
lab var yrd7 "Year=1998"
lab var yrd8 "Year=1999"
lab var yrd9 "Year=2000"
lab var yrd10 "Year=2001"
lab var yrd11 "Year=2002"
lab var yrd12 "Year=2003"
lab var yrd13 "Year=2004"
lab var yrd14 "Year=2005"
lab var yrd15 "Year=2006"
lab var yrd16 "Year=2007"
lab var yrd17 "Year=2008"
lab var yrd18 "Year=2009"
lab var yrd19 "Year=2010"
lab var yrd20 "Year=2011"
lab var yrd21 "Year=2012"
lab var yrd22 "Year=2013"
lab var yrd23 "Year=2014"
lab var yrd24 "Year=2015"
lab var yrd25 "Year=2016"
lab var yrd26 "Year=2017"
lab var yrd27 "Year=2018"
lab var yrd28 "Year=2019"
lab var yrd29 "Year=2020"

lab var bsx1 "BS=Musculoskeletal"
lab var bsx2 "BS=Respiratory"   
lab var bsx3 "BS=Cardiov."   
lab var bsx4 "BS=Endocrine"       
lab var bsx5 "BS=Neurol."
lab var bsx6 "BS=Mental dis."
lab var bsx7 "BS=Cancer"    
lab var bsx8 "BS=Immune def."  
lab var bsx9 "BS=Dig. and Urin." 
lab var bsx10 "BS=Other"
 
lab var doctor_told_has_hbp "Was told to have high blood press." 
lab var doctor_told_has_psy "Was told to have psych. cond."
lab var doctor_told_has_hea "Was told to have heart cond."
lab var doctor_told_has_art "Was told to have arthritis"
lab var doctor_told_has_dia "Was told to have diabetes"
lab var doctor_told_has_lun "Was told to have lung disease"
lab var doctor_told_has_str "Was told to have stroke"
lab var doctor_told_has_can "Was told to have cancer"

label var walkra "Difficulty walking across room"
label var dressa "Difficulty dressing"
label var stoopa "Difficulty stooping, kneeling or crouching"
label var beda "Difficulty getting out of bed"

lab var walkra_appl_1 "ADL, diff. walking"
lab var dressa_appl_1 "ADL, diff. dressing" 
lab var stoopa_appl_1 "ADL, diff. stooping, kneeling, crouching"
lab var beda_appl_1   "ADL, diff. getting out of bed"
lab var hosp_appl_1   "Some nights in hosp."
lab var bmi_appl	  "BMI"	

lab var longestoccx1  "Occupation=unknown/miss"
lab var longestoccx2  "Occupation=managerial specialty oper"
lab var longestoccx3  "Occupation=prof specialty opr/tech sup"
lab var longestoccx4  "Occupation=sales"
lab var longestoccx5  "Occupation=clerical/admin supp"
lab var longestoccx6  "Occupation=svc:protection"
lab var longestoccx7  "Occupation=svc:food prep"
lab var longestoccx8  "Occupation=health svc"
lab var longestoccx9  "Occupation=personal svc"
lab var longestoccx10 "Occupation=farming/forestry/fishing"
lab var longestoccx11 "Occupation=mechanics/repair"
lab var longestoccx12 "Occupation=constr trade/extractors"
lab var longestoccx13 "Occupation=precision production"
lab var longestoccx14 "Occupation=operators: machine"
lab var longestoccx15 "Occupation=operators: transport, etc"
lab var longestoccx16 "Occupation=operators: handlers, etc"

gen 	occ_for_table=1 if longest_occ_combined_x>=1 & longest_occ_combined_x<=4
replace occ_for_table=2 if longest_occ_combined_x>=5 & longest_occ_combined_x<=9
replace occ_for_table=3 if longest_occ_combined_x>=10 & longest_occ_combined_x<=17
replace occ_for_table=4 if longest_occ_combined_x==0
label def occ_for_table 1 "Clerical occupation" 2 "Services occupation" 3 "Blue collar occupation" 4 "Occupation unknown/other"
label values occ_for_table occ_for_table
tab occ_for_table,gen(occ_for_table_x)
lab var occ_for_table_x1  "Clerical occupation"
lab var occ_for_table_x2  "Services occupation"
lab var occ_for_table_x3  "Blue collar occupation"
lab var occ_for_table_x4  "Occupation unknown/other"



**************************************************************************************************
**************************************************************************************************
**** TABLE 1
**************************************************************************************************
**************************************************************************************************
eststo clear
eststo s0: estpost tabstat nosuccess type1 type2 nosuccess_cycle type1_cycle type2_cycle cantwork_notemp_appl someworklim ssi_only ssi_and_di college racex2 married_appl widowed_appl experience age ///
	occ_for_table_x1 occ_for_table_x2 occ_for_table_x3 occ_for_table_x4 bsx1 bsx2 bsx3 bsx4 bsx5 bsx6 bsx7 bsx8 bsx9 bsx10  ///
	if sample==1 & cantwork_notemp_appl !=. & female==0, statistics(mean sd) columns(statistics) 
eststo s1: estpost tabstat nosuccess type1 type2 nosuccess_cycle type1_cycle type2_cycle cantwork_notemp_appl someworklim ssi_only ssi_and_di college racex2 married_appl widowed_appl experience age ///
	occ_for_table_x1 occ_for_table_x2 occ_for_table_x3 occ_for_table_x4 bsx1 bsx2 bsx3 bsx4 bsx5 bsx6 bsx7 bsx8 bsx9 bsx10  ///
	if sample==1 & cantwork_notemp_appl !=. & female==1, statistics(mean sd) columns(statistics)
eststo sa: estpost tabstat nosuccess type1 type2 nosuccess_cycle type1_cycle type2_cycle cantwork_notemp_appl someworklim ssi_only ssi_and_di college racex2 married_appl widowed_appl experience age ///
	occ_for_table_x1 occ_for_table_x2 occ_for_table_x3 occ_for_table_x4 bsx1 bsx2 bsx3 bsx4 bsx5 bsx6 bsx7 bsx8 bsx9 bsx10  ///
	if sample==1 & cantwork_notemp_appl !=. , statistics(mean sd) columns(statistics)
esttab s0 s1 sa using $figures\table1.tex,   ///
	 cells("mean(fmt(2)) sd(fmt(2))")  nodepvar label unstack mtitle("Men" "Women" "All") nonumber ///
	 title("Descriptive statistics" \label{tab1}) replace ///
	 postfoot(\hline\hline \end{tabular} { \\ \begin{flushleft} \begin{scriptsize} \textit{Note:} Sample includes all first-round applications (of all application cycles) observed in F831 data with non-missing data on self-reported ///
	 health limitation. \textit{Health lmtn} is a dummy that equals one if individual self-reported a health condition that is not temporary and stops work altogether. The sample sizes for Type I (II) errors represent all individuals ///
	 who applied for DI or SSI and self-reported a health limitation (no limitation). \end{scriptsize} \end{flushleft} } \end{table} )
eststo clear


*******************************************************************************************************************************************************************************	
*******************************************************************************************************************************************************************************	 
				 
**************************************************************************************************
**************************************************************************************************
**** TABLE 2
**************************************************************************************************
**************************************************************************************************
eststo clear 

* TYPE 1	
probit nosuccess 	$spec2 if cantwork_notemp_appl==1  & sample==1, vce(cluster hhidpn) 
eststo, addscalars(Healthlmtn 1): estpost margins, dydx(*)

probit nosuccess 	$spec3 if cantwork_notemp_appl==1  & sample==1, vce(cluster hhidpn) 
eststo, addscalars(Healthlmtn 1): estpost margins, dydx(*)

probit nosuccess 	$spec4 if cantwork_notemp_appl==1  & sample==1, vce(cluster hhidpn) 
testparm longestoccx*
scalar def occup_pval=r(p) 
estpost margins, dydx(*)
eststo, addscalars(Healthlmtn 1 occup_pval occup_pval)


* TYPE 2
xi: qui probit success 	$spec2 if cantwork_notemp_appl==0  & sample==1, vce(cluster hhidpn) 
eststo, addscalars(Healthlmtn 0): estpost margins, dydx(*)

xi: probit success 	$spec3 if cantwork_notemp_appl==0  & sample==1, vce(cluster hhidpn) 
eststo, addscalars(Healthlmtn 0): estpost margins, dydx(*)

xi: probit success	$spec4 if cantwork_notemp_appl == 0 & sample==1, vce(cluster hhidpn)  /*can we use occ==0 as additional, "N/A" category" ???*/
testparm longestoccx*
scalar def occup_pval=r(p) 
estpost margins, dydx(*)
eststo, addscalars(Healthlmtn 0 occup_pval occup_pval)

esttab using $figures\table2.tex, se ///
	scalars(occup_pval) b(%9.3f) se(%9.3f) sfmt(%9.3f) star(* 0.10 ** 0.05 *** 0.01) ///
	mgroups("Type I error" "Type II error", pattern (1 0 0 1 0 0)) mlabels(none) ///
	label title("Probit regressions for Type I and Type II errors"  \label{tab3})  replace ///
	indicate("Year FE=*yrd*" "F831 disab. FE=*bsx*" "HRS Objective FE = *doctor*"  "ADL FE = walkra*" "BMI+Hosp = bmi_a*" "Occupation FE = longestocc*")  ///
	keep(female college racex2 experience ssi_only ssi_and_di married_appl widowed_appl age) ///
	 postfoot(\hline\hline \end{tabular} { \\ \begin{flushleft} \begin{scriptsize} \textit{Note:} Standard errors in parentheses, clustered at the individual level. The reported coefficients are marginal effects. Labor market experience is number of years with positive earnings (from the MEF dataset). The "F831 disab. FE" refer to the primary disability codes of SSI/DI applicants (see Table 1);the HRS Obj. FE refer to the doctor-diagnosed conditions of Table 2; the ADL FE refer to indicators for difficulty with activity-of-daily-leaving (see Table 2); BMI+Hosp are dummies for extreme BMI levels or hospitalization. The occupations dummies are described in footnote 22. ***, **, and * mean significance at 1, 5 and 10 percent level, respectively. \end{scriptsize} \end{flushleft} } \end{table} )	 
**************************************************************************************************


**************************************************************************************************
**************************************************************************************************
**** TABLE 3
**************************************************************************************************
**************************************************************************************************
gen rejected_12 = reject_step == 1 | reject_step == 2| reject_step==0
label var rejected_12 "Rejected stages 1/2"

gen rejected_45 = reject_step == 4 | reject_step == 5 
label var rejected_45 "Rejected stages 4/5"

eststo clear

sum rejected_12 if cantwork_notemp_appl == 1 & sample==1					/*DV=1 if rejected at med.st., 0=decided at later stage*/
scalar def sample_avg=r(mean)

/*Eliminate a perfect collinearity issue - occ=10 explains failure perfectly - only for this regression*/
g occ_step=longest_occ_combined_appl
replace occ_step=12 if occ_step==10
drop longestoccx*
tab occ_step,gen(longestoccx)
drop occ_step

xi: dprobit rejected_12	female college racex2 experience bsx2 bsx3 bsx4 bsx5 bsx6 bsx7 bsx8 bsx9 bsx10 ///
						doctor* ssi_only ssi_and_di married_appl widowed_appl age yrd* ///
						walkra_appl_1 dressa_appl_1 stoopa_appl_1 beda_appl_1 hosp_appl_1 bmi_appl ///
						longestoccx* if cantwork_notemp_appl == 1 & sample==1, vce(cluster hhidpn)
eststo, addscalars(Sample_avg sample_avg): estpost margins, dydx(*)

sum rejected_45 if cantwork_notemp_appl == 1 & sample==1 & rejected_12 == 0		/*DV=1 if rejected at voc.st., 0=awarded*/
scalar def sample_avg=r(mean)
drop longestoccx*
tab longest_occ_combined_appl,gen(longestoccx)

xi: dprobit rejected_45	female college racex2 experience bsx2 bsx3 bsx4 bsx5 bsx6 bsx7 bsx8 bsx9 bsx10 ///
						doctor* ssi_only ssi_and_di married_appl widowed_appl age yrd* ///
						walkra_appl_1 dressa_appl_1 stoopa_appl_1 beda_appl_1 hosp_appl_1 bmi_appl ///
						longestoccx* if cantwork_notemp_appl == 1 & sample==1 & rejected_12 == 0, vce(cluster hhidpn)
eststo, addscalars(Sample_avg sample_avg): estpost margins, dydx(*)

esttab using $figures\table3.tex, se ///
	indicate("Year FE=*yrd*"  "HRS Objective FE = *doctor*" "Health cond. FE=*bsx*"  "ADL FE = walkra*" "BMI+Hosp = bmi_a*" "Occupation FE = longestocc*") ///
	mtitle("Medical stage" "Vocational stage") scalars(Sample_avg) ///
	b(%9.3f) se(%9.3f) sfmt(%9.3f) star(* 0.10 ** 0.05 *** 0.01) ///
	keep(female college racex2 experience ssi_only ssi_and_di married_appl widowed_appl age) ///
	label title("Type I errors: Rejection at medical or vocational stage")  replace ///
	 postfoot(\hline\hline \end{tabular} { \\ \begin{flushleft} \begin{scriptsize} \textit{Note:} Standard errors in parentheses, clustered at the individual level. The reported coefficients are merginal effects. ***, **, and * means significance at 1, 5 and 10 percent level, respectively. In column (1) the outcome variable equals 1 if rejection is due to not meeting "medical criteria" (i.e. impairment is deemed not severe or not expected to last 12 months or more). In column (2) the outcome variable equals 1 if rejection is due to not meeting "vocational criteria" (i.e., SSA determines that there is capacity for SGA - past relevant work, or capacity for SGA - other work). See notes to table 3 for a detailed description of the controls. \end{scriptsize} \end{flushleft} } \end{table} )

**************************************************************************************************
**************************************************************************************************
**** TABLE 4
**************************************************************************************************
**************************************************************************************************
eststo clear

* col 1 - Baseline
sum nosuccess if cantwork_notemp_appl == 1 & sample==1
scalar def sample_avg=r(mean)
probit nosuccess 	$spec4 if cantwork_notemp_appl==1  & sample==1, vce(cluster hhidpn) 
eststo, addscalars(sample_avg sample_avg): estpost margins, dydx(female) 

* col 2 - DI sample
sum nosuccess if cantwork_notemp_appl == 1 & sample==1 & rid!=16
scalar def sample_avg=r(mean)
probit nosuccess $spec4 if cantwork_notemp_appl == 1 & sample==1 & rid!=16, vce(cluster hhidpn)
eststo, addscalars(sample_avg sample_avg): estpost margins, dydx(female) 

* col 3 - 2<=d<=12
preserve
	u $data\sampleB,clear
	** bandwidths: 2 mos before or 12 after
	drop yrd*
	replace year=1994 if year==1995
	qui tab year,gen(yrd)
	global spec4 female college racex2 experience bsx2 bsx3 bsx4 bsx5 bsx6 bsx7 bsx8 bsx9 bsx10 ssi_only ssi_and_di married_appl widowed_appl age yrd* ///
				 doctor* walkra_appl_1 dressa_appl_1 stoopa_appl_1 beda_appl_1 hosp_appl_1 bmi_appl longestoccx*
	sum nosuccess if cantwork_notemp_appl == 1 & sample==1
	scalar def sample_avg=r(mean)
	probit nosuccess 	$spec4 if cantwork_notemp_appl==1  & sample==1, vce(cluster hhidpn) 
	eststo, addscalars(sample_avg sample_avg): estpost margins, dydx(female) 
restore

* col 4- 0<=d<=12, but weighted 
gen wts = 12 - floor(days_to_interview_appl/31) //weight more if closer to interview in mos
gen wtssqr = sqrt(wts)

sum nosuccess if cantwork_notemp_appl == 1 & sample==1 [iweight = wtssqr]
scalar def sample_avg=r(mean)
probit nosuccess $spec4 if cantwork_notemp_appl==1 & sample==1 [iweight = wtssqr], vce(cluster hhidpn)
eststo, addscalars(sample_avg sample_avg): estpost margins, dydx(female)
drop wts*

* col 5 - disabled if at least 2 ADL disab
egen adlsum = rsum(walkra_appl dressa_appl stoopa_appl beda_appl) //number of ADL inabilities
gen adl_lim = adlsum >= 2
sum nosuccess if adl_lim == 1 & sample==1
scalar def sample_avg=r(mean)
probit nosuccess	$spec4 if adl_lim == 1 & sample==1, vce(cluster hhidpn)
eststo, addscalars(sample_avg sample_avg): estpost margins, dydx(female)	 

* col 6 - predicted 
cap drop ppp
qui probit cantwork_notemp_appl bsx2 bsx3 bsx4 bsx5 bsx6 bsx7 bsx8 bsx9 bsx10 doctor* walkra_appl_1 dressa_appl_1 stoopa_appl_1 beda_appl_1 hosp_appl_1 bmi_appl 
predict ppp,pr
su ppp if success==1
scalar E_ppp_success=r(mean)
sum nosuccess if ppp>=E_ppp_success  & sample==1
scalar def sample_avg=r(mean)
probit nosuccess 	$spec5 if ppp>=E_ppp_success  & sample==1, vce(cluster hhidpn)	/*Type I using propensity score*/
eststo, addscalars(sample_avg sample_avg): estpost margins, dydx(female)  


esttab using $figures\table4.tex, se ///
keep(female) mtitle("Baseline" "DI only" "$-2\leq d\leq 12$" "$0\leq d \leq 12$, weighted" "Two ADL+" "Predicted") ///
label title("Probit regressions for Type I errors: Robustness (1)"  \label{tab6}) replace ///
 postfoot(\hline\hline \end{tabular} { \\ \begin{flushleft} \begin{scriptsize} \textit{Note:} Standard errors in parentheses, clustered at the individual level. The reported coefficients are marginal effects. All regressions include the controls of Table 3, column (3). See notes to that table for a detailed description of the controls. ***, **, and * means significance at 1, 5 and 10 percent level, respectively. \end{scriptsize} \end{flushleft} } \end{table} ) ///
 scalars(sample_avg)  cells("b(fmt(%9.3f) star)" se(par fmt(%9.3f))) sfmt(%9.2f) star(* 0.10 ** 0.05 *** 0.01)

	
drop adlsum adl_lim ppp
	
	
**************************************************************************************************
**************************************************************************************************
**** TABLE B.1
**************************************************************************************************
**************************************************************************************************

eststo clear

* col 1 - baseline
sum nosuccess if cantwork_notemp_appl == 1 & sample==1
scalar def sample_avg=r(mean)
probit nosuccess 	$spec4 if cantwork_notemp_appl==1  & sample==1, vce(cluster hhidpn) 
eststo, title("Baseline") addscalars(sample_avg sample_avg): estpost margins, dydx(female)	 

** col.2 - type 1/2 over app cycle
sum nosuccess_cycle if cantwork_notemp_appl == 1 & sample==1
scalar def sample_avg=r(mean)
probit nosuccess_cycle $spec4 if cantwork_notemp_appl == 1 & sample==1, vce(cluster hhidpn)
eststo, title("Cycle") addscalars(sample_avg sample_avg): estpost margins, dydx(female )

*******EVER SUCCESSFUL?
sort hhidpn
merge hhidpn using  $data\ever_received_di_or_ssi
tab _merge
drop if _merge!=3
drop _merge

gen nosuccess_ever=ever_received_di_or_ssi==0 & nosuccess==1

/*some year dummies predict outcome perfectly - aggregate some adjacent years*/
gen year_restr=year
replace year_restr=1993 if year==1992
replace year_restr=2004 if year==2003
replace year_restr=2007 if year==2006
tab year_restr,gen(yrdr)

sum nosuccess_ever 
scalar def sample_avg=r(mean)
* col 3 - never successful 	 
probit nosuccess_ever 	female college racex2 experience ssi_only ssi_and_di married_appl widowed_appl age yrdr* bsx2 bsx3 bsx4 bsx5 bsx6 bsx7 bsx8 bsx9 bsx10 ///
			 doctor* walkra_appl_1 dressa_appl_1 stoopa_appl_1 beda_appl_1 hosp_appl_1 bmi_appl longestoccx* if cantwork_notemp_appl==1  & sample==1, vce(cluster hhidpn) 
eststo, title("Never succ.") addscalars(sample_avg sample_avg): estpost margins, dydx(female)
drop year_restr yrdr*


* col 4 - within 9 months 	 
sum nosuccess if cantwork_notemp_appl == 1 & sample==1 & within_9mo==1
scalar def sample_avg=r(mean)
xi: probit nosuccess $spec4 if cantwork_notemp_appl==1 & sample==1 & within_9mo == 1, vce(cluster hhidpn)
eststo, title("0<=d<=9") addscalars(sample_avg sample_avg): estpost margins, dydx(female)

* col 5 - binary definition
sum nosuccess if someworklim == 1 & sample==1
scalar def sample_avg=r(mean)
probit nosuccess	$spec4 if someworklim == 1 & sample==1, vce(cluster hhidpn)
eststo, title("Binary") addscalars(sample_avg sample_avg): estpost margins, dydx(female)	 

* col 6	- mca  
cap drop pmca_1
gen obese1=bmi_appl>=30 & bmi_appl<.
gen overw1=bmi_appl>=25 & bmi_appl<30
gen underw1=bmi_appl<=18.5
qui mca bsx2 bsx3 bsx4 bsx5 bsx6 bsx7 bsx8 bsx9 bsx10 doctor* walkra_appl_1 dressa_appl_1 stoopa_appl_1 beda_appl_1 hosp_appl_1 obese1 underw1 overw1
predict pmca_1
su pmca_1 if success==1
scalar E_pmca_success=r(mean)
sum nosuccess if pmca>=E_pmca_success  & sample==1
scalar def sample_avg=r(mean)
dprobit nosuccess 	$spec5 if pmca>=E_pmca_success  & sample==1, vce(cluster hhidpn)	/*Type I using propsensity score*/
eststo, title("MCA") addscalars(sample_avg sample_avg): estpost margins, dydx(female)  
	 
esttab using $figures\tableB1.tex, se ///
keep(female) mtitle("Baseline" "Cycle" "Never succ." "$0\leq d\leq 9$" "Binary" "MCA") ///	 
label title("Probit regressions for Type I errors: Robustness (2)"  \label{tab7}) replace ///
scalars(sample_avg) sfmt(%9.2f) star(* 0.10 ** 0.05 *** 0.01) ///
	 postfoot(\hline\hline \end{tabular} { \\ \begin{flushleft} \begin{scriptsize} \textit{Note:} Standard errors in parentheses, clustered at the individual level. The reported coefficients are marginal effects. In column (2) we classify as work disabled those who report to have an impairment or health problem that limits the kind or amount of paid work they can do. In column (3) dep. var. equals one if applicant was never successful. In column (4) we assume that an individual is work disabled if he/she reports difficulties with two or more activities of daily living. In column (5) we use the predicted value of a regression of the subjective disability indicator on clinical and objective indicators. Finally, in column (6) we use an MCA analysis for the clinical/objective disability indicators \end{scriptsize} \end{flushleft} } \end{table} ) ///
	 b(%9.3f) se(%9.3f) 
	 
drop obese1 overw1 underw1 pmca_1
	 
**************************************************************************************************
**************************************************************************************************
**** TABLE B.2
**************************************************************************************************
**************************************************************************************************
eststo clear	
*(column 1 is baseline repeated)
sum nosuccess if cantwork_notemp_appl == 1 & sample==1
scalar def sample_avg=r(mean)
probit nosuccess 	$spec4 if cantwork_notemp_appl==1  & sample==1, vce(cluster hhidpn) 
eststo , title("Baseline") addscalars(sample_avg sample_avg): estpost margins, dydx(female) 
			 
**************************************************************************************************
*****************************************************************TABLE B.2, column 2 *************
**************************************************************************************************
gen age_less_than_50=age<50
gen age_50_54		=age>=50 & age<=54
gen age_55_59		=age>=55 & age<=59
gen age_60_plus		=age>=60

probit nosuccess	female college racex2 experience bsx2 bsx3 bsx4 bsx5 bsx6 bsx7 bsx8 bsx9 bsx10 ///
						doctor* ssi_only ssi_and_di married_appl widowed_appl age_50-age_60_plus yrd* ///
						walkra_appl_1 dressa_appl_1 stoopa_appl_1 beda_appl_1 hosp_appl_1 bmi_appl ///
						longestoccx* if cantwork_notemp_appl == 1 & sample==1, vce(cluster hhidpn)  /*can we use occ==0 as additional, "N/A" category" ???*/
eststo , title("Age splines") addscalars(sample_avg sample_avg): estpost margins, dydx(female age_50_54 age_55_59 age_60_plus) 
 
**************************************************************************************************
*****************************************************************TABLE B.2, column 3 *************
**************************************************************************************************
//physical PCA
sum nosuccess if cantwork_notemp_appl == 1 & sample==1
scalar def sample_avg=r(mean)
probit nosuccess	female college racex2 experience bsx2 bsx3 bsx4 bsx5 bsx6 bsx7 bsx8 bsx9 bsx10 ///
						doctor* ssi_only ssi_and_di married_appl widowed_appl age yrd* ///
						walkra_appl_1 dressa_appl_1 stoopa_appl_1 beda_appl_1 hosp_appl_1 bmi_appl ///
						PhysPC1_appl if cantwork_notemp_appl == 1 & sample==1, vce(cluster hhidpn)
eststo , title("ONet") addscalars(sample_avg sample_avg): estpost margins, dydx(female PhysPC1_appl)
gen onetsample=e(sample) 

**************************************************************************************************
*****************************************************************TABLE B.2, column 4 *************
**************************************************************************************************
gen married_female=married_appl*female
g employed_spouse=(hh_ern_real-earn_real)>0
g husbempl_female=employed_spouse*female

sum nosuccess if cantwork_notemp_appl == 1 & sample==1
scalar def sample_avg=r(mean)
probit nosuccess	female husbempl_female married_female college racex2 experience bsx2 bsx3 bsx4 bsx5 bsx6 bsx7 bsx8 bsx9 bsx10 ///
						doctor* ssi_only ssi_and_di married_appl widowed_appl age yrd* ///
						walkra_appl_1 dressa_appl_1 stoopa_appl_1 beda_appl_1 hosp_appl_1 bmi_appl ///
						longestoccx* if cantwork_notemp_appl == 1 & sample==1, vce(cluster hhidpn)
eststo , title("Husband work") addscalars(sample_avg sample_avg): estpost margins, dydx(female husbempl_female married_female) 

**************************************************************************************************
*****************************************************************TABLE B.2, column 5 *************
**************************************************************************************************
sort hhidpn year record
merge hhidpn year record using $data\primary_earner
drop if _merge!=3
drop _merge

replace avgy=avgy/1000
sum nosuccess if cantwork_notemp_appl == 1 & sample==1
scalar def sample_avg=r(mean)

lab var age_less_than_50 "Age $\lt$ 50"
lab var age_50_54		 "50 $\le$ Age $\le$ 54"
lab var age_55_59		 "55 $\le$ Age $\le$ 59"
lab var age_60_plus		 "Age $\ge$ 60"
lab var PhysPC1_appl 	 "First principal component ONet"
lab var married_female	 "Married female"
lab var employed_spouse  "Spouse employed"
lab var husbempl_female  "Female applicant w/ empl. spouse"
lab var avgy 			 "Avg. earnings 5 years before applic."
lab var primary_earner   "Applicant is primary arner"


probit nosuccess 	$spec4 avgy primary_earner if cantwork_notemp_appl==1  & sample==1, vce(cluster hhidpn) 
eststo , title("Primary earn") addscalars(sample_avg sample_avg): estpost margins, dydx(female avgy primary_earner)
 
esttab using $figures\tableB2.tex, se mtitle("Baseline" "Age splines" "ONet" "Husband work" "Primary earner") ///
	cells("b(fmt(%9.3f) star)" se(par fmt(%9.3f))) scalars(sample_avg) sfmt(%9.2f) star(* 0.10 ** 0.05 *** 0.01)  ///
	label title("Additional Results"  \label{taba1}) replace  ///
	postfoot(\hline\hline \end{tabular} ///
	{ \\ \begin{flushleft} \begin{scriptsize} \textit{Note:} Standard errors in parentheses, clustered at the individual level.\end{scriptsize} \end{flushleft} } \end{table} )

drop onetsample	

**************************************************************************************************
**************************************************************************************************
**** FIGURE 1
**************************************************************************************************
**************************************************************************************************
u $data\sampleA,clear
cd $figures	

drop hlthlm_appl
rename cantwork_notemp_appl hlthlm_appl

//backwards compat
gen educ = college + 1
g race = raracem==1
replace race = 2 - white

*group some body systems together
label def bs_group 1 "Verifiable"  2 "Non-verifiable" 
gen bs_group = .
replace bs_group = 2 if bs==1 | bs==12 | bs==16
replace bs_group = 1 if bs_group==. & bs!=.
label values bs_group bs_group

tab bs_group,gen(bsd)
lab var bsd1 "Verifiable conditions"  
lab var bsd2 "Non-verifiable conditions"  
lab var female "Female"
lab var nosuccess "No award, app. round"
lab var hlthlm_appl "Work disabled"

label def occ_group 1 "Predominantly Female Occupations"  2 "Predominantly Male Occupations" 
gen occ_group = .
replace occ_group = 1 if longest_occ_combined_x>=1 & longest_occ_combined_x<=9
replace occ_group = 2 if (longest_occ_combined_x>=10 & longest_occ_combined_x<=17)|longest_occ_combined_x==0
label values occ_group occ_group
tab occ_group,gen(occd)
lab var occd1 "Predominantly Female Occupations"  
lab var occd2 "Predominantly Male Occupations"  


*raw means
egen type1_female = mean(nosuccess) if female==1 & hlthlm_appl==1
egen type1_male   = mean(nosuccess) if female==0 & hlthlm_appl==1

* by condition
gen t1=.
gen t2=.
replace t1=1 if hlthlm_appl==1 & success==0
replace t1=0 if hlthlm_appl==1 & success==1
replace t2=1 if hlthlm_appl==0 & success==1
replace t2=0 if hlthlm_appl==0 & success==0

foreach i in t1 t2 { 

	foreach x in bs_group ragender {
		bysort `x': egen `i'_`x'_sh = mean(`i')
		bysort `x': replace `i'_`x'_sh = . if _n>1
		bysort `x': egen `i'_`x'_n = total(`i'!=.)
		bysort `x': replace `i'_`x'_n = . if _n>1
		gen `i'_`x'_ci_l =`i'_`x'_sh - 1.96*sqrt(`i'_`x'_sh*(1-`i'_`x'_sh)/`i'_`x'_n)
		gen `i'_`x'_ci_u =`i'_`x'_sh + 1.96*sqrt(`i'_`x'_sh*(1-`i'_`x'_sh)/`i'_`x'_n)
	}	
}

* by educ and gender
foreach i in t1 t2 { 
	foreach y in ragender {
		bysort educ `y': egen `i'_educ_sh_`y' = mean(`i')
		bysort educ `y': replace `i'_educ_sh_`y' = . if _n>1		
		bysort educ `y': egen `i'_educ_n_`y' = total(`i'!=.)
		bysort educ `y': replace `i'_educ_n_`y' = . if _n>1
		gen `i'_educ_ci_l_`y' = `i'_educ_sh_`y' - 1.96*sqrt(`i'_educ_sh_`y'*(1-`i'_educ_sh_`y')/`i'_educ_n_`y')
		gen `i'_educ_ci_u_`y' = `i'_educ_sh_`y' + 1.96*sqrt(`i'_educ_sh_`y'*(1-`i'_educ_sh_`y')/`i'_educ_n_`y')
	}
}

* by condition and gender/race/educ
foreach i in t1 t2 { 
	foreach y in ragender race educ {
		bysort bs_group `y': egen `i'_sh_`y' = mean(`i')
		bysort bs_group `y': replace `i'_sh_`y' = . if _n>1		
		bysort bs_group `y': egen `i'_n_`y' = total(`i'!=.)
		bysort bs_group `y': replace `i'_n_`y' = . if _n>1
		gen `i'_ci_l_`y' = `i'_sh_`y' - 1.96*sqrt(`i'_sh_`y'*(1-`i'_sh_`y')/`i'_n_`y')
		gen `i'_ci_u_`y' = `i'_sh_`y' + 1.96*sqrt(`i'_sh_`y'*(1-`i'_sh_`y')/`i'_n_`y')
		
	}
	
}

sort t1_bs_group_sh

*** Type I / II by condition and gender
gen     bsgender = ragender   if bs_group==1
replace bsgender = ragender+3 if bs_group==2

**** Figure 1
twoway (bar t1_sh_ragender bsgender if ragender==1, graphr(c(white))) ///
	 (bar t1_sh_ragender bsgender if ragender==2) ///
	 (rcap t1_ci_u_ragender t1_ci_l_ragender bsgender) if bs_group !=., ///
	 legend(order (1 "Men" 2 "Women")) ///
	 xscale(range(1 5)) xlabel(1.5 `" "Verifiable Conditions" "' 4.5 `" "Non-Verifiable Conditions" "',labsize(small)) ///
	 xtitle("") ///
	 name(f1, replace) ytitle("") legend(region(lcolor(none)) pos(6) col(2)) saving(f1,replace)

******************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
u $data\sampleA,clear
cd $figures	

drop hlthlm_appl
rename cantwork_notemp_appl hlthlm_appl

//backwards compat
gen educ = college + 1
g race = raracem==1
replace race = 2 - white

label def occ_group 1 "Predominantly Female Occupations"  2 "Predominantly Male Occupations" 
gen occ_group = .
replace occ_group = 1 if longest_occ_combined_x>=1 & longest_occ_combined_x<=9
replace occ_group = 2 if (longest_occ_combined_x>=10 & longest_occ_combined_x<=17)|longest_occ_combined_x==0
label values occ_group occ_group
tab occ_group,gen(occd)
lab var occd1 "Predominantly Female Occupations"  
lab var occd2 "Predominantly Male Occupations"  

*raw means
egen type1_female = mean(nosuccess) if female==1 & hlthlm_appl==1
egen type1_male   = mean(nosuccess) if female==0 & hlthlm_appl==1

* by condition
gen t1=.
gen t2=.
replace t1=1 if hlthlm_appl==1 & success==0
replace t1=0 if hlthlm_appl==1 & success==1
replace t2=1 if hlthlm_appl==0 & success==1
replace t2=0 if hlthlm_appl==0 & success==0

foreach i in t1 t2 { 

	foreach x in occ_group ragender {
		bysort `x': egen `i'_`x'_sh = mean(`i')
		bysort `x': replace `i'_`x'_sh = . if _n>1
		bysort `x': egen `i'_`x'_n = total(`i'!=.)
		bysort `x': replace `i'_`x'_n = . if _n>1
		gen `i'_`x'_ci_l =`i'_`x'_sh - 1.96*sqrt(`i'_`x'_sh*(1-`i'_`x'_sh)/`i'_`x'_n)
		gen `i'_`x'_ci_u =`i'_`x'_sh + 1.96*sqrt(`i'_`x'_sh*(1-`i'_`x'_sh)/`i'_`x'_n)
	}	
}

* by educ and gender
foreach i in t1 t2 { 
	foreach y in ragender {
		bysort educ `y': egen `i'_educ_sh_`y' = mean(`i')
		bysort educ `y': replace `i'_educ_sh_`y' = . if _n>1		
		bysort educ `y': egen `i'_educ_n_`y' = total(`i'!=.)
		bysort educ `y': replace `i'_educ_n_`y' = . if _n>1
		gen `i'_educ_ci_l_`y' = `i'_educ_sh_`y' - 1.96*sqrt(`i'_educ_sh_`y'*(1-`i'_educ_sh_`y')/`i'_educ_n_`y')
		gen `i'_educ_ci_u_`y' = `i'_educ_sh_`y' + 1.96*sqrt(`i'_educ_sh_`y'*(1-`i'_educ_sh_`y')/`i'_educ_n_`y')
	}
}

* by condition and gender/race/educ
foreach i in t1 t2 { 
	foreach y in ragender race educ {
		bysort occ_group `y': egen `i'_sh_`y' = mean(`i')
		bysort occ_group `y': replace `i'_sh_`y' = . if _n>1		
		bysort occ_group `y': egen `i'_n_`y' = total(`i'!=.)
		bysort occ_group `y': replace `i'_n_`y' = . if _n>1
		gen `i'_ci_l_`y' = `i'_sh_`y' - 1.96*sqrt(`i'_sh_`y'*(1-`i'_sh_`y')/`i'_n_`y')
		gen `i'_ci_u_`y' = `i'_sh_`y' + 1.96*sqrt(`i'_sh_`y'*(1-`i'_sh_`y')/`i'_n_`y')
		
	}
	
}

sort t1_occ_group_sh

*** Type I / II by condition and gender
gen     occgender = ragender   if occ_group==1
replace occgender = ragender+3 if occ_group==2

**** Figure 1
twoway (bar t1_sh_ragender occgender if ragender==1, graphr(c(white))) ///
	 (bar t1_sh_ragender occgender if ragender==2) ///
	 (rcap t1_ci_u_ragender t1_ci_l_ragender occgender) if occ_group !=., ///
	 legend(order (1 "Men" 2 "Women")) ///
	 xscale(range(1 5)) xlabel(1.5 `" "Predominantly Female Occup." "' 4.5 `" "Predominantly Male Occup." "',labsize(small)) ///
	 xtitle("") ///
	 name(f2, replace) ytitle("") legend(region(lcolor(none)) pos(6) col(2)) saving(f2,replace)

graph combine f1.gph f2.gph,graphr(c(white))
graph export $figures\figure1.pdf, replace

erase  $figures\f1.gph
erase  $figures\f2.gph

******************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
	

**************************************************************************************************
**************************************************************************************************
**** TABLE 10
**************************************************************************************************
**************************************************************************************************
u $data\sampleA_labor_future,clear

replace year=1994 if year==1995		/*aggregate b/c of small cell size*/
qui tab year,gen(yrd)

eststo clear

lab var experience "Experience"
lab var ssi_only "Applied SSI only"
lab var ssi_and_di "Applied DI and SSI"
lab var yrd1 "Year=1991"
lab var yrd2 "Year=1992"
lab var yrd3 "Year=1993"
lab var yrd4 "Year=1994-95"
lab var yrd5 "Year=1996"
lab var yrd6 "Year=1997"
lab var yrd7 "Year=1998"
lab var yrd8 "Year=1999"
lab var yrd9 "Year=2000"
lab var yrd10 "Year=2001"
lab var yrd11 "Year=2002"
lab var yrd12 "Year=2003"
lab var yrd13 "Year=2004"
lab var yrd14 "Year=2005"
lab var yrd15 "Year=2006"
lab var yrd16 "Year=2007"
lab var yrd17 "Year=2008"
lab var yrd18 "Year=2009"
lab var yrd19 "Year=2010"
lab var yrd20 "Year=2011"
lab var yrd21 "Year=2012"
lab var yrd22 "Year=2013"
lab var yrd23 "Year=2014"
lab var yrd24 "Year=2015"
lab var yrd25 "Year=2016"
lab var yrd26 "Year=2017"
lab var yrd27 "Year=2018"
lab var yrd28 "Year=2019"
lab var yrd29 "Year=2020"

lab var longestoccx1  "Occ.=unknown/miss"
lab var longestoccx2  "Occ.=manag. specialty oper"
lab var longestoccx3  "Occ.=prof spec. opr/tech sup"
lab var longestoccx4  "Occ.=sales"
lab var longestoccx5  "Occ.=cler./admin supp"
lab var longestoccx6  "Occ.=svc:protection"
lab var longestoccx7  "Occ.=svc:food prep"
lab var longestoccx8  "Occ.=health svc"
lab var longestoccx9  "Occ.=personal svc"
lab var longestoccx10 "Occ.=farm/for/fish"
lab var longestoccx11 "Occ.=mech./repair"
lab var longestoccx12 "Occ.=constr trade/extract."
lab var longestoccx13 "Occ.=precision production"
lab var longestoccx14 "Occ.=oper.: machine"
lab var longestoccx15 "Occ.=oper.: transport, etc"
lab var longestoccx16 "Occ.=oper.: handlers, etc"

lab var bsx1 "BS=Musculoskeletal"
lab var bsx2 "BS=Respiratory"   
lab var bsx3 "BS=Cardiov."   
lab var bsx4 "BS=Endocrine"       
lab var bsx5 "BS=Neurol."
lab var bsx6 "BS=Mental dis."
lab var bsx7 "BS=Cancer"    
lab var bsx8 "BS=Immune def."  
lab var bsx9 "BS=Dig. and Urin." 
lab var bsx10 "BS=Other"
lab var female "Female"
lab var college "College"
lab var age "Age"
lab var married_appl "Married"
lab var widowed_appl "Widowed"

lab var racex2 "Black"
 
lab var doctor_told_has_hbp "Was told to have high blood press." 
lab var doctor_told_has_psy "Was told to have psych. cond."
lab var doctor_told_has_hea "Was told to have heart cond."
lab var doctor_told_has_art "Was told to have arthritis"
lab var doctor_told_has_dia "Was told to have diabetes"
lab var doctor_told_has_lun "Was told to have lung disease"
lab var doctor_told_has_str "Was told to have stroke"
lab var doctor_told_has_can "Was told to have cancer"

label var walkra "Difficulty walking across room"
label var dressa "Difficulty dressing"
label var stoopa "Difficulty stooping, kneeling or crouching"
label var beda "Difficulty getting out of bed"
lab var walkra_appl "ADL, diff. walking"
lab var dressa_appl "ADL, diff. dressing" 
lab var stoopa_appl "ADL, diff. stooping, kneeling, crouching"
lab var beda_appl   "ADL, diff. getting out of bed"
lab var hosp_appl   "Some nights in hosp."
lab var bmi_appl	  "BMI"	

lab var earn_sga_3 "Earn above SGA 1 to 3 years after dec."
gen R=rejected
gen F=female
gen L=cantwork_notemp_appl
gen RL=R*L
gen RF=R*F
gen FL=F*L
gen RFL=R*F*L

lab var R 	"Rejected"
lab var F 	"Female"
lab var L 	"Work disabled"
lab var RL 	"Rejected x Work disabled"
lab var RF 	"Rejected x Female"
lab var FL 	"Female x Work disabled"
lab var RFL "Rejected x Female x Work disabled"

*Future:	F,R,FR (10(1))
*Future:	F,R,L,FL,FR,LR,FRL (10(2))
*Past:		F,R,L,FL,FR,LR,FRL (10(3))
*Future:	R,L,RL (A2(1))
*Past:		R,L,RL (A2(2))


global spec_empl college racex2 experience doctor* ssi_only ssi_and_di married_appl widowed_appl age walkra_appl dressa_appl stoopa_appl beda_appl hosp_appl bmi_appl yrd*						

/*Table A2, col. 1*/
qui reghdfe earn_sga_3 R L RL $spec_empl , vce(cluster hhidpn) abs( longest_occ_combined_appl bs)
su earn_sga_3 if e(sample) 
scalar Avg=r(mean)
su earn_sga_3 if e(sample) & rejected==1 & cantwork_notemp_appl==1
scalar Avg_R1L1=r(mean)
su earn_sga_3 if e(sample) & rejected==1 & cantwork_notemp_appl==0
scalar Avg_R1L0=r(mean)
su earn_sga_3 if e(sample) & rejected==0 & cantwork_notemp_appl==1
scalar Avg_R0L1=r(mean)
su earn_sga_3 if e(sample) & rejected==0 & cantwork_notemp_appl==0
scalar Avg_R0L0=r(mean)
eststo tabA2_1, addscalars(Avg Avg AvgR1L1 Avg_R1L1 AvgR1L0 Avg_R1L0 AvgR0L1 Avg_R0L1 AvgR0L0 Avg_R0L0) title("Bound test, after") : estpost margins, dydx(R L RL) 

/*Table 10 col 1*/
qui reghdfe earn_sga_3 F R RF $spec_empl, vce(cluster hhidpn) abs( longest_occ_combined_appl bs)
eststo tab10_1, addscalars(Avg Avg AvgR1L1 Avg_R1L1 AvgR1L0 Avg_R1L0 AvgR0L1 Avg_R0L1 AvgR0L0 Avg_R0L0) title("Test 1, after"): estpost margins, dydx(F R RF)

/*Table 10 col 2*/
qui reghdfe earn_sga_3 F R L RL RF FL RFL $spec_empl, vce(cluster hhidpn) abs( longest_occ_combined_appl bs)
lincom _b[F]+_b[R]+_b[RF]	/*referee's point*/
lincom _b[F]+_b[RF]

eststo tab10_2, addscalars(Avg Avg AvgR1L1 Avg_R1L1 AvgR1L0 Avg_R1L0 AvgR0L1 Avg_R0L1 AvgR0L0 Avg_R0L0) title("Test 2, after"): estpost margins, dydx(F R L RL RF FL RFL)


***************************************
u $data\sampleA_labor_past,clear

replace year=1994 if year==1995		/*small cell size*/
qui tab year,gen(yrd)

lab var experience "Experience"
lab var ssi_only "Applied SSI only"
lab var ssi_and_di "Applied DI and SSI"

lab var yrd1 "Year=1991"
lab var yrd2 "Year=1992"
lab var yrd3 "Year=1993"
lab var yrd4 "Year=1994-95"
lab var yrd5 "Year=1996"
lab var yrd6 "Year=1997"
lab var yrd7 "Year=1998"
lab var yrd8 "Year=1999"
lab var yrd9 "Year=2000"
lab var yrd10 "Year=2001"
lab var yrd11 "Year=2002"
lab var yrd12 "Year=2003"
lab var yrd13 "Year=2004"
lab var yrd14 "Year=2005"
lab var yrd15 "Year=2006"
lab var yrd16 "Year=2007"
lab var yrd17 "Year=2008"
lab var yrd18 "Year=2009"
lab var yrd19 "Year=2010"
lab var yrd20 "Year=2011"
lab var yrd21 "Year=2012"
lab var yrd22 "Year=2013"
lab var yrd23 "Year=2014"
lab var yrd24 "Year=2015"
lab var yrd25 "Year=2016"
lab var yrd26 "Year=2017"
lab var yrd27 "Year=2018"
lab var yrd28 "Year=2019"
lab var yrd29 "Year=2020"

lab var longestoccx1  "Occ.=unknown/miss"
lab var longestoccx2  "Occ.=manag. specialty oper"
lab var longestoccx3  "Occ.=prof spec. opr/tech sup"
lab var longestoccx4  "Occ.=sales"
lab var longestoccx5  "Occ.=cler./admin supp"
lab var longestoccx6  "Occ.=svc:protection"
lab var longestoccx7  "Occ.=svc:food prep"
lab var longestoccx8  "Occ.=health svc"
lab var longestoccx9  "Occ.=personal svc"
lab var longestoccx10 "Occ.=farm/for/fish"
lab var longestoccx11 "Occ.=mech./repair"
lab var longestoccx12 "Occ.=constr trade/extract."
lab var longestoccx13 "Occ.=precision production"
lab var longestoccx14 "Occ.=oper.: machine"
lab var longestoccx15 "Occ.=oper.: transport, etc"
lab var longestoccx16 "Occ.=oper.: handlers, etc"

lab var bsx1 "BS=Musculoskeletal"
lab var bsx2 "BS=Respiratory"   
lab var bsx3 "BS=Cardiov."   
lab var bsx4 "BS=Endocrine"       
lab var bsx5 "BS=Neurol."
lab var bsx6 "BS=Mental dis."
lab var bsx7 "BS=Cancer"    
lab var bsx8 "BS=Immune def."  
lab var bsx9 "BS=Dig. and Urin." 
lab var bsx10 "BS=Other"
 
lab var doctor_told_has_hbp "Was told to have high blood press." 
lab var doctor_told_has_psy "Was told to have psych. cond."
lab var doctor_told_has_hea "Was told to have heart cond."
lab var doctor_told_has_art "Was told to have arthritis"
lab var doctor_told_has_dia "Was told to have diabetes"
lab var doctor_told_has_lun "Was told to have lung disease"
lab var doctor_told_has_str "Was told to have stroke"
lab var doctor_told_has_can "Was told to have cancer"

label var walkra "Difficulty walking across room"
label var dressa "Difficulty dressing"
label var stoopa "Difficulty stooping, kneeling or crouching"
label var beda "Difficulty getting out of bed"
lab var female "Female"
lab var college "College"
lab var age "Age"
lab var married_appl "Married"
lab var widowed_appl "Widowed"
lab var racex2 "Black"

lab var walkra_appl "ADL, diff. walking"
lab var dressa_appl "ADL, diff. dressing" 
lab var stoopa_appl "ADL, diff. stooping, kneeling, crouching"
lab var beda_appl   "ADL, diff. getting out of bed"
lab var hosp_appl   "Some nights in hosp."
lab var bmi_appl	  "BMI"	


lab var bmi_appl	  "BMI"	
lab var earn_past_sga "Earn above SGA 5 to 10 yrs before dec."

gen R=rejected
gen F=female
gen L=cantwork_notemp_appl
gen RL=R*L
gen RF=R*F
gen FL=F*L
gen RFL=R*F*L

lab var R "Rejected"
lab var F "Female"
lab var L "Work disabled"
lab var RL "Rejected x Work disabled"
lab var RF "Rejected x Female"
lab var FL "Female x Work disabled"
lab var RFL "Rejected x Female x Work disabled"


global spec_empl college racex2 experience doctor* ssi_only ssi_and_di married_appl widowed_appl age walkra_appl dressa_appl stoopa_appl beda_appl hosp_appl bmi_appl yrd*						

**** TABLE 10, col 3
reghdfe earn_past_sga R L RL $spec_empl , vce(cluster hhidpn) abs( longest_occ_combined_appl bs)
su earn_past_sga if e(sample) 
scalar def Avg=r(mean)
su earn_past_sga if e(sample) & rejected==1 & cantwork_notemp_appl==1
scalar def Avg_R1L1=r(mean)
su earn_past_sga if e(sample) & rejected==1 & cantwork_notemp_appl==0
scalar def Avg_R1L0=r(mean)
su earn_past_sga if e(sample) & rejected==0 & cantwork_notemp_appl==1
scalar def Avg_R0L1=r(mean)
su earn_past_sga if e(sample) & rejected==0 & cantwork_notemp_appl==0
scalar def Avg_R0L0=r(mean)	
eststo tabA2_2, addscalars(Avg Avg AvgR1L1 Avg_R1L1 AvgR1L0 Avg_R1L0 AvgR0L1 Avg_R0L1 AvgR0L0 Avg_R0L0) title("Bound test, before") : estpost margins, dydx(R L RL) 

**** TABLE 10, col 3
qui reghdfe earn_past_sga F R L RL RF FL RFL $spec_empl, vce(cluster hhidpn) abs( longest_occ_combined_appl bs)
eststo tab10_3, addscalars(Avg Avg AvgR1L1 Avg_R1L1 AvgR1L0 Avg_R1L0 AvgR0L1 Avg_R0L1 AvgR0L0 Avg_R0L0) title("Test 2, before"): estpost margins, dydx(F R L RL RF FL RFL)

			
esttab tab10_1 tab10_2 tab10_3 using $figures\table10.tex, se ///
	mtitle("1-3 yrs aft" "1-3 yrs aft" "5-10 yrs bef" ) ///
	cells("b(fmt(%9.3f) star)" se(par fmt(%9.3f)))  star(* 0.10 ** 0.05 *** 0.01)  ///
	mgroups("Test 1" "Test 2", pattern (1 1 0))  scalars(Avg AvgR1L1 AvgR1L0 AvgR0L1 AvgR0L0) b(%9.3f) se(%9.3f) sfmt(%9.2f) ///
	label title("Impact of SSA Decision on Subsequent Work"  \label{tab10}) replace  ///
	postfoot(\hline\hline \end{tabular} { \\ \begin{flushleft} \begin{scriptsize} \textit{Note:} Standard errors in parentheses, clustered at the individual level. Dependent variable is employment, defined as earning at least as much as the SGA. Respondents are defined as "Work disabled" if they report to have an impairment or health problem that limits the kind or amount of paid work they can do; if the condition is not temporary (i.e., lasting less than three months); and if the limitation keeps them from working altogether. ***, **, and * means significance at 1, 5 and 10 percent level, respectively. See notes to Table 3 for a detailed description of the controls. \end{scriptsize} \end{flushleft} } \end{table} )
	

esttab tabA2_1 tabA2_2 using $figures\tableA2.tex, se ///
	mtitle("1-3 yrs aft" "5-10 yrs bef" ) ///
	cells("b(fmt(%9.3f) star)" se(par fmt(%9.3f)))  star(* 0.10 ** 0.05 *** 0.01)  ///
	scalars(Avg AvgR1L1 AvgR1L0 AvgR0L1 AvgR0L0) b(%9.3f) se(%9.3f) sfmt(%9.2f) ///
	label title("Impact of SSA Decision on Subsequent Work"  \label{taba2}) replace  ///
	postfoot(\hline\hline \end{tabular} { \\ \begin{flushleft} \begin{scriptsize} \textit{Note:} Standard errors in parentheses, clustered at the individual level. Dependent variable is employment, defined as earning at least as much as the SGA. Respondents are defined as "Work disabled" if they report to have an impairment or health problem that limits the kind or amount of paid work they can do; if the condition is not temporary (i.e., lasting less than three months); and if the limitation keeps them from working altogether. ***, **, and * means significance at 1, 5 and 10 percent level, respectively. See notes to Table 3 for a detailed description of the controls. \end{scriptsize} \end{flushleft} } \end{table} )

	
	
**************************************************************************************************
**************************************************************************************************
**** TABLE A.1
**************************************************************************************************
**************************************************************************************************
cd $data
u sampleC.dta, clear
cd $figures

xtset hhidpn wave
gen cantwork_prev = L.cantwork_notemp

label var cantwork_notemp "Disabled t"
label var cantwork_prev "Disabled t-1"
label var racex2 "Black"

sort hhidpn, stable

label def hlthlims 0 "No health lmtn" 1 "Health lmtn"
label val hlthlm hlthlims
label val cantwork_notemp hlthlims
label var walkra "Difficulty walking across room"
label var dressa "Difficulty dressing"
label var stoopa "Difficulty stooping, kneeling or crouching"
label var beda "Difficulty getting out of bed"
label var shopa "Difficulty grocery shopping"
label var mealsa "Difficulty preparing meals" 
label var hosp "Hospital stay"
label var hspnit "Nights in hospital"
label var hibp "Has high blood pressure"
label var psych "Has psychological condition"
label var heart "Has heart condition"
label var arthr "Has arthritis"
label var diab "Has diabetes"
label var lung "Has lung condition"
label var strok "Had stroke"
label var cancr "Has cancer"
label var obese "Obese"
label var underwt "Underweight"
label var oopmd_intvw_real "OOP spending"

global vars_to_sum walkra dressa stoopa beda shopa mealsa hosp hspnit obese underwt hibp psych heart arthr diab lung strok cancr oopmd_intvw_real 

	**Women
			matrix results = J(21,8,.)
			matrix rownames results = "Difficulty walking" "... dressing" "... stooping, etc." "... getting out of bed" "... grocery shopping" "... preparing meals" "Hospital stay" "Nights in hospital"  "Obese" "Underweight" "Doctor diagnosed HBP" ///
										"... psychological condition" "... heart condition" "... arthritis" "... diabetes" "... lung condition" "... stroke" "... cancer" "Health spending" ///
										 "Died in sample" "N"
			matrix colnames results = "F, no lim." "F, lim." "F, reg." "P-val" "M, no lim." "M, lim." "M, reg." "P-val" 

			local r = 1
			foreach y of varlist  $vars_to_sum {
				disp `r'
					quietly su `y' if female==1 & cantwork_notemp==0 
				matrix results[`r',1] = r(mean)
				local r = `r' + 1
			}

	preserve
			duplicates drop hhidpn, force
			gen died_in_sample = year_died !=.
			quietly su died_in_sample if female==1 & cantwork_notemp==0 
			matrix results[20,1] = r(mean)
	restore

	qui su female if female==1 & cantwork_notemp==0
	matrix results[21,1] = r(N)
	
			local r = 1
			foreach y of varlist  $vars_to_sum {
				disp `r'
					quietly su `y' if female==1 & cantwork_notemp==1 
				matrix results[`r',2] = r(mean)
				local r = `r' + 1
			}

	preserve
			duplicates drop hhidpn, force
			gen died_in_sample = year_died !=.
			quietly su died_in_sample if female==1 & cantwork_notemp==1 
			matrix results[20,2] = r(mean)
	restore

	qui su female if female==1 & cantwork_notemp==1
	matrix results[21,2] = r(N)

	local r = 1
			foreach y of varlist  $vars_to_sum {
				disp `r'
					quietly reg `y' age i.cantwork_notemp if female==1 , vce(cluster hhidpn)
				matrix results[`r',3] = e(b)[1,3]
				matrix results[`r',4] = r(table)[4,3]
				local r = `r' + 1
			}
	quietly reg walkra age i.cantwork_notemp if female==1 , vce(cluster hhidpn)
	

	preserve
			duplicates drop hhidpn, force
			gen died_in_sample = year_died !=.
			quietly reg died_in_sample age i.cantwork_notemp if female==1 , vce(cluster hhidpn)
			matrix results[20,3] = e(b)[1,3]
			matrix results[20,4] = r(table)[4,3]
	restore

	**Men
			
			local r = 1
			foreach y of varlist  $vars_to_sum {
				disp `r'
					quietly su `y' if female==0 & cantwork_notemp==0 
				matrix results[`r',5] = r(mean)
				local r = `r' + 1
			}

	preserve
			duplicates drop hhidpn, force
			gen died_in_sample = year_died !=.
			quietly su died_in_sample if female==0 & cantwork_notemp==0 
			matrix results[20,5] = r(mean)
	restore

	qui su female if female==0 & cantwork_notemp==0
	matrix results[21,5] = r(N)

			local r = 1
			foreach y of varlist  $vars_to_sum {
				disp `r'
					quietly su `y' if female==0 & cantwork_notemp==1 
				matrix results[`r',6] = r(mean)
				local r = `r' + 1
			}

	preserve
			duplicates drop hhidpn, force
			gen died_in_sample = year_died !=.
			quietly su died_in_sample if female==0 & cantwork_notemp==1 
			matrix results[20,6] = r(mean)
	restore

	qui su female if female==0 & cantwork_notemp==1
	matrix results[21,6] = r(N)

			local r = 1
			foreach y of varlist  $vars_to_sum {
				disp `r'
					quietly reg `y' age i.cantwork_notemp if female==0 , vce(cluster hhidpn)
				matrix results[`r',7] = e(b)[1,3]
				matrix results[`r',8] = r(table)[4,3]
				local r = `r' + 1
			}

	preserve
			duplicates drop hhidpn, force
			gen died_in_sample = year_died !=.
			quietly reg died_in_sample age i.cantwork_notemp if female==0 , vce(cluster hhidpn)
			matrix results[20,7] = e(b)[1,3]
			matrix results[20,8] = r(table)[4,3]
	restore
	matrix results[21,3]=50258
	matrix results[21,7]=32128
	
**** TABLE A1: DIFFERENCES IN OBJECTIVE CONDITIONS BY HEALTH LIMITATION (This uses public-use HRS data)
esttab matrix(results, fmt(%9.2f)) using "$figures/tableA1.tex", ///
					title("Health variables by self-reported work disability status and gender") collabels("Non work-dis." "Work dis." "$\Delta$ (regr.)" "P-val." "Non work-dis." "Work dis." "$\Delta$ (regr.)" "P-val.") replace ///
					postfoot(\hline\hline \end{tabular} { \\ \begin{flushleft} \begin{scriptsize} \textit{Note:} Unit of observation is a person-HRS wave for all variables except death, where it is just person. Respondents are defined as "work disabled" if they report to have an impairment or health problem that limits the kind or amount of paid work they can do; if the condition is not temporary (i.e., lasting less than three months); and if the limitation keeps them from working altogether. In the third and sixth columns we use regression analysis and report the marginal effect of the dummy for being disabled on the row variable (controlling for age). *** means significance at 1 percent level (s.e. clustered at the individual level). The sample is individuals aged 20-65 only. \end{scriptsize} \end{flushleft} } \end{table} )
										
			eststo clear


**************************************************************************************************
**************************************************************************************************
**** TABLE OA.1
**************************************************************************************************
**************************************************************************************************
tab wave,gen(waved)
forvalues j=1(1)15	{
	lab var waved`j' "HRS wave `j'"
}

lab var cantwork_notemp "Work disabled(t)"
lab var cantwork_prev "Work disabled(t-1)"
gen cantwork_prev_female=cantwork_prev*female
lab var cantwork_prev_female "Work disabled(t-1)*Female"
lab var longestoccx1   "Occupation=Unknown/missing"
lab var longestoccx2   "Occupation=Managerial specialty oper"
lab var longestoccx3   "Occupation=Prof specialty opr/tech sup"
lab var longestoccx4   "Occupation=Sales"
lab var longestoccx5   "Occupation=Clerical/admin supp"
lab var longestoccx6   "Occupation=Svc:prv hhld/clean/bldg svc"
lab var longestoccx7   "Occupation=Svc:protection"
lab var longestoccx8   "Occupation=Svc:food prep"
lab var longestoccx9   "Occupation=Health svc"
lab var longestoccx10  "Occupation=Personal svc"
lab var longestoccx11  "Occupation=Farming/forestry/fishing"
lab var longestoccx12  "Occupation=Mechanics/repair"
lab var longestoccx13  "Occupation=Constr trade/extractors"
lab var longestoccx14  "Occupation=Precision production"
lab var longestoccx15  "Occupation=Operators: machine"
lab var longestoccx16  "Occupation=Operators: transport, etc"
lab var longestoccx17  "Occupation=Operators: handlers, etc"
lab var longestoccx18  "Occupation=Member of armed forces"

lab var hibp "Was told to have high blood press." 
lab var psych "Was told to have psych. cond."
lab var heart "Was told to have heart cond."
lab var arthr "Was told to have arthritis"
lab var diab "Was told to have diabetes"
lab var lung "Was told to have lung disease"
lab var strok "Was told to have stroke"
lab var cancr "Was told to have cancer"

label var walkra "Difficulty walking across room"
label var dressa "Difficulty dressing"
label var stoopa "Difficulty stooping, kneeling or crouching"
label var beda "Difficulty getting out of bed"

lab var female "Female"
lab var college "College"
lab var age "Age"
lab var married "Married"
lab var widowed "Widowed"
lab var racex2 "Black"

eststo clear
eststo: reg cantwork_notemp cantwork_prev , vce(cluster hhidpn)
gen AR1sample=e(sample)
eststo: reg cantwork_notemp cantwork_prev female cantwork_prev_female , vce(cluster hhidpn)
eststo: reg cantwork_notemp cantwork_prev female cantwork_prev_female college married widowed racex2 age waved* /// 
			cancr strok lung diab arthr heart psych hibp walkra dressa stoopa beda hosp bmi ///
			longestoccx* , vce(cluster hhidpn)
gen AR1sample_restr=e(sample)
esttab using $figures\tableOA1.tex, se ///
	indicate("Wave FE=*wave*" "BMI + Hosp=bmi" "Health + ADL FE=cancr" "Occupation FE = longestoccx*") ///
	b(%9.3f) se(%9.3f) sfmt(%9.3f) star(* 0.10 ** 0.05 *** 0.01)  ///
	keep(cantwork_prev female cantwork_prev_female college racex2 married widowed age) ///
	label title("Disability transition by gender, ages 20-65"  \label{tab5}) replace ///
	 postfoot(\hline\hline \end{tabular} { \\ \begin{flushleft} \begin{scriptsize} \textit{Note:} Standard errors in parentheses, clustered at the individual level. \end{scriptsize} \end{flushleft} } \end{table} )
eststo clear



					
**************TABLE OA.4
cd $data
u sampleA.dta, clear

******************************************************************************************************************************************************
global spec4 female college racex2 experience ssi_only ssi_and_di married_appl widowed_appl age yrd* bsx2 bsx3 bsx4 bsx5 bsx6 bsx7 bsx8 bsx9 bsx10 ///
			 doctor* walkra_appl_1 dressa_appl_1 stoopa_appl_1 beda_appl_1 hosp_appl_1 bmi_appl longestoccx*
global spec5 female college racex2 experience ssi_only ssi_and_di married_appl widowed_appl age yrd* longestoccx*
******************************************************************************************************************************************************

cap drop ppp
qui probit cantwork_notemp_appl bsx2 bsx3 bsx4 bsx5 bsx6 bsx7 bsx8 bsx9 bsx10 doctor* walkra_appl_1 dressa_appl_1 stoopa_appl_1 beda_appl_1 hosp_appl_1 bmi_appl 
predict ppp,pr
su ppp if success==1
scalar E_ppp_success=r(mean)
gen alt_disab_def1=ppp>=E_ppp_success  & sample==1 & ppp!=.

cap drop ppp
qui probit cantwork_notemp_appl bsx2 bsx3 bsx4 bsx5 bsx6 bsx7 bsx8 bsx9 bsx10 doctor* walkra_appl_1 dressa_appl_1 stoopa_appl_1 beda_appl_1 hosp_appl_1 bmi_appl if female==1
predict ppp,pr
su ppp if success==1
scalar E_ppp_success=r(mean)
gen alt_disab_def2=ppp>=E_ppp_success  & sample==1 & ppp!=.

cap drop pmca_1
gen obese1=bmi_appl>=30 & bmi_appl<.
gen overw1=bmi_appl>=25 & bmi_appl<30
gen underw1=bmi_appl<=18.5
qui mca bsx2 bsx3 bsx4 bsx5 bsx6 bsx7 bsx8 bsx9 bsx10 doctor* walkra_appl_1 dressa_appl_1 stoopa_appl_1 beda_appl_1 hosp_appl_1 obese1 underw1 overw1
predict pmca_1
su pmca_1 if success==1
scalar E_pmca_success=r(mean)
gen alt_disab_def3=pmca>=E_pmca_success  & sample==1 & pmca_1!=.
drop obese1 overw1 underw1 pmca_1

pwcorr cantwork_notemp_appl  alt_d*

eststo clear

lab var yrd1 "Year=1991"
lab var yrd2 "Year=1992"
lab var yrd3 "Year=1993"
lab var yrd4 "Year=1994-95"
lab var yrd5 "Year=1996"
lab var yrd6 "Year=1997"
lab var yrd7 "Year=1998"
lab var yrd8 "Year=1999"
lab var yrd9 "Year=2000"
lab var yrd10 "Year=2001"
lab var yrd11 "Year=2002"
lab var yrd12 "Year=2003"
lab var yrd13 "Year=2004"
lab var yrd14 "Year=2005"
lab var yrd15 "Year=2006"
lab var yrd16 "Year=2007"
lab var yrd17 "Year=2008"
lab var yrd18 "Year=2009"
lab var yrd19 "Year=2010"
lab var yrd20 "Year=2011"
lab var yrd21 "Year=2012"
lab var yrd22 "Year=2013"
lab var yrd23 "Year=2014"
lab var yrd24 "Year=2015"
lab var yrd25 "Year=2016"
lab var yrd26 "Year=2017"
lab var yrd27 "Year=2018"
lab var yrd28 "Year=2019"
lab var yrd29 "Year=2020"

lab var longestoccx1  "Occ.=unknown/miss"
lab var longestoccx2  "Occ.=manag. specialty oper"
lab var longestoccx3  "Occ.=prof spec. opr/tech sup"
lab var longestoccx4  "Occ.=sales"
lab var longestoccx5  "Occ.=cler./admin supp"
lab var longestoccx6  "Occ.=svc:protection"
lab var longestoccx7  "Occ.=svc:food prep"
lab var longestoccx8  "Occ.=health svc"
lab var longestoccx9  "Occ.=personal svc"
lab var longestoccx10 "Occ.=farm/for/fish"
lab var longestoccx11 "Occ.=mech./repair"
lab var longestoccx12 "Occ.=constr trade/extract."
lab var longestoccx13 "Occ.=precision production"
lab var longestoccx14 "Occ.=oper.: machine"
lab var longestoccx15 "Occ.=oper.: transport, etc"
lab var longestoccx16 "Occ.=oper.: handlers, etc"

***TYpe I results
xi: probit nosuccess	$spec4 if cantwork_notemp_appl==1  & sample==1, vce(cluster hhidpn)  
eststo t1_1: estpost margins, dydx(female)
xi: probit nosuccess	$spec5 if alt_disab_def1 == 1 & sample==1, vce(cluster hhidpn)  
eststo t1_2: estpost margins, dydx(female)
xi: probit nosuccess	$spec5 if alt_disab_def2 == 1 & sample==1, vce(cluster hhidpn)  
eststo t1_3: estpost margins, dydx(female)
xi: probit nosuccess	$spec5 if alt_disab_def3 == 1 & sample==1, vce(cluster hhidpn)  
eststo t1_4: estpost margins, dydx(female)

***TYpe II results
xi: probit success	$spec4 if cantwork_notemp_appl==0 & sample==1, vce(cluster hhidpn)  
eststo t2_1: estpost margins, dydx(female)
xi: probit success	$spec5 if alt_disab_def1 == 0 & sample==1, vce(cluster hhidpn)  
eststo t2_2: estpost margins, dydx(female)
xi: probit success	$spec5 if alt_disab_def2 == 0 & sample==1, vce(cluster hhidpn)  
eststo t2_3: estpost margins, dydx(female)
xi: probit success	$spec5 if alt_disab_def3 == 0 & sample==1, vce(cluster hhidpn)  
eststo t2_4: estpost margins, dydx(female)

***Rejected at stages 1-2 vs 4-5
gen rejected_12 = reject_step == 1 | reject_step == 2| reject_step==0
label var rejected_12 "Rejected 1/2"
gen rejected_45 = reject_step == 4 | reject_step == 5 
label var rejected_45 "Rejected 4/5"

***
g occ_step=longest_occ_combined_appl
replace occ_step=12 if occ_step==10	/*cell size*/
tab occ_step,gen(longestoccx_step)
xi: probit rejected_12 female college racex2 experience bsx2 bsx3 bsx4 bsx5 bsx6 bsx7 bsx8 bsx9 bsx10 ///
						doctor* ssi_only ssi_and_di married_appl widowed_appl age yrd* ///
						walkra_appl_1 dressa_appl_1 stoopa_appl_1 beda_appl_1 hosp_appl_1 bmi_appl ///
						longestoccx_step*	 if cantwork_notemp_appl == 1 & sample==1, vce(cluster hhidpn)
eststo med_1: estpost margins, dydx(female)
drop occ_step longestoccx_step*
xi: probit rejected_12	$spec5 if alt_disab_def1 == 1 & sample==1, vce(cluster hhidpn)
eststo med_2: estpost margins, dydx(female)
xi: probit rejected_12	$spec5 if alt_disab_def2 == 1 & sample==1, vce(cluster hhidpn)
eststo med_3: estpost margins, dydx(female)
xi: probit rejected_12	$spec5 if alt_disab_def3 == 1 & sample==1, vce(cluster hhidpn)
eststo med_4: estpost margins, dydx(female)

 
xi: probit rejected_45 $spec4 if cantwork_notemp_appl == 1 & sample==1 & rejected_12 == 0, vce(cluster hhidpn)
eststo voc_1: estpost margins, dydx(female)
xi: probit rejected_45 $spec5 if alt_disab_def1 == 1 & sample==1 & rejected_12 == 0, vce(cluster hhidpn)
eststo voc_2: estpost margins, dydx(female)
xi: probit rejected_45 $spec5 if alt_disab_def2 == 1 & sample==1 & rejected_12 == 0, vce(cluster hhidpn)
eststo voc_3: estpost margins, dydx(female)
xi: probit rejected_45 $spec5 if alt_disab_def3 == 1 & sample==1 & rejected_12 == 0, vce(cluster hhidpn)
eststo voc_4: estpost margins, dydx(female)

keep hhidpn year alt_disab_def*
sort hhidpn year
duplicates drop hhidpn year ,force
save $data\alt_disab_def,replace


u $data\sampleA_labor_future,clear

drop _merge
sort hhidpn year
merge 1:1 hhidpn year using $data\alt_disab_def
drop if _merge==2

replace year=1994 if year==1995		/*small cell size*/
qui tab year,gen(yrd)

lab var earn_sga_3 "Earn above SGA 1 to 3 years after dec."
gen R=rejected
gen F=female
gen L=cantwork_notemp_appl
gen RL=R*L
gen RF=R*F
gen FL=F*L
gen RFL=R*F*L

global spec_empl college racex2 experience doctor* ssi_only ssi_and_di married_appl widowed_appl age walkra_appl dressa_appl stoopa_appl beda_appl hosp_appl bmi_appl yrd*						

qui reghdfe earn_sga_3 R L rejected_limited $spec_empl , vce(cluster hhidpn) abs( longest_occ_combined_appl bs)
eststo ls_1: estpost margins, dydx(rejected_limited) 

replace rejected_limited=rejected*alt_disab_def1
reghdfe earn_sga_3 rejected rejected_limited alt_disab_def1 female college racex2 experience ///
						ssi_only ssi_and_di married_appl widowed_appl age ///
						, vce(cluster hhidpn) abs(year longest_occ_combined_appl)
eststo ls_2: estpost margins, dydx(rejected_limited) 
replace rejected_limited=rejected*alt_disab_def2
reghdfe earn_sga_3 rejected rejected_limited alt_disab_def2 female college racex2 experience ///
						ssi_only ssi_and_di married_appl widowed_appl age ///
						, vce(cluster hhidpn) abs(year longest_occ_combined_appl)
eststo ls_3: estpost margins, dydx(rejected_limited) 
replace rejected_limited=rejected*alt_disab_def3
reghdfe earn_sga_3 rejected rejected_limited alt_disab_def3 female college racex2 experience ///
						ssi_only ssi_and_di married_appl widowed_appl age ///
						, vce(cluster hhidpn) abs(year longest_occ_combined_appl)
eststo ls_4: estpost margins, dydx(rejected_limited) 

esttab t1_1 t1_2 t1_3 t1_4 using $figures\tableOA4_1.tex, se ///
	mtitle("Baseline" "Alt Def 1" "Alt Def 2" "Alt Def 3" ) ///
	cells("b(fmt(%9.3f) star)" se(par fmt(%9.3f)))  star(* 0.10 ** 0.05 *** 0.01)  ///
	label title("Type I results"  \label{tab10}) replace  ///
	postfoot(\hline\hline \end{tabular} { \\ \begin{flushleft} \begin{scriptsize} \textit{Note:} Standard errors in parentheses, clustered at the individual level. \end{scriptsize} \end{flushleft} } \end{table} )
esttab t2_1 t2_2 t2_3 t2_4 using $figures\tableOA4_2.tex, se ///
	mtitle("Baseline" "Alt Def 1" "Alt Def 2" "Alt Def 3" ) ///
	cells("b(fmt(%9.3f) star)" se(par fmt(%9.3f)))  star(* 0.10 ** 0.05 *** 0.01)  ///
	label title("Type II results"  \label{tab10}) replace  ///
	postfoot(\hline\hline \end{tabular} { \\ \begin{flushleft} \begin{scriptsize} \textit{Note:} Standard errors in parentheses, clustered at the individual level. \end{scriptsize} \end{flushleft} } \end{table} )
esttab med_1 med_2 med_3 med_4 using $figures\tableOA4_3.tex, se ///
	mtitle("Baseline" "Alt Def 1" "Alt Def 2" "Alt Def 3" ) ///
	cells("b(fmt(%9.3f) star)" se(par fmt(%9.3f)))  star(* 0.10 ** 0.05 *** 0.01)  ///
	label title("Med.Rej. results"  \label{tab10}) replace  ///
	postfoot(\hline\hline \end{tabular} { \\ \begin{flushleft} \begin{scriptsize} \textit{Note:} Standard errors in parentheses, clustered at the individual level. \end{scriptsize} \end{flushleft} } \end{table} )
esttab voc_1 voc_2 voc_3 voc_4 using $figures\tableOA4_4.tex, se ///
	mtitle("Baseline" "Alt Def 1" "Alt Def 2" "Alt Def 3" ) ///
	cells("b(fmt(%9.3f) star)" se(par fmt(%9.3f)))  star(* 0.10 ** 0.05 *** 0.01)  ///
	label title("Voc.Rej. results"  \label{tab10}) replace  ///
	postfoot(\hline\hline \end{tabular} { \\ \begin{flushleft} \begin{scriptsize} \textit{Note:} Standard errors in parentheses, clustered at the individual level. \end{scriptsize} \end{flushleft} } \end{table} )
esttab ls_1 ls_2 ls_3 ls_4 using $figures\tableOA4_5.tex, se ///
	mtitle("Baseline" "Alt Def 1" "Alt Def 2" "Alt Def 3" ) ///
	cells("b(fmt(%9.3f) star)" se(par fmt(%9.3f)))  star(* 0.10 ** 0.05 *** 0.01)  ///
	label title("Lab.Supply results"  \label{tab10}) replace  ///
	postfoot(\hline\hline \end{tabular} { \\ \begin{flushleft} \begin{scriptsize} \textit{Note:} Standard errors in parentheses, clustered at the individual level. \end{scriptsize} \end{flushleft} } \end{table} )
		

	
	
*********
cd $data
u sampleA.dta, clear

****Precision of signal INDIRECT EVIDENCE - 
eststo clear 
gen insuff_evid=(rb==36|rb==93|rb==94)
su insuff_evid
scalar def Avg=r(mean)
probit 	insuff $spec4,vce(cluster hhidpn)
eststo r1, addscalars(Avg Avg): estpost margins, dydx(female ) 


****assigned to CE **** extra controls to add below 	 
gen govt_hins=(higov_appl==1)
gen priv_hins=(prpcnt_appl>0 & prpcnt_appl<.)|(hiothp_appl==1)|(covr_appl==1)
gen logbs=log(1+itot_appl+achck_appl+astck_appl+acd_appl+abond_appl)

lab var logbs "Log of liquid resources"  
lab var govt_hins "Has govt. health ins."
lab var priv_hins "Has priv. health ins."

gen CErequest=cer==1
su CErequest  
scalar def Avg=r(mean)
lab var CErequest "Requested cons. exam." 

probit 	CErequest $spec4,vce(cluster hhidpn)
eststo r2, addscalars(Avg Avg): estpost margins, dydx(female) 

probit 	CErequest $spec4 govt_hins priv_hins logbs,vce(cluster hhidpn) 
eststo r3, addscalars(Avg Avg): estpost margins, dydx(female) 

esttab r1 r2 r3 using $figures\tableOA2.tex, se scalars(Avg Avg) ///
	sfmt(%9.2f) cells("b(fmt(%9.3f) star)" se(par fmt(%9.3f))) star(* 0.10 ** 0.05 *** 0.01)  ///
	keep(female) ///
	label title("Precision of Signal: Probit model for insufficient evidence or evidence request"  \label{signal}) replace ///
	 postfoot(\hline\hline \end{tabular} { \\ \begin{flushleft} \begin{scriptsize} \textit{Note:} Standard errors in parentheses, clustered at the individual level. Coefficients are estimates of marginal effects. \textit{experience} is years with non-zero wage income. \end{scriptsize} \end{flushleft} } \end{table} )	

	 
 
**************************************************************************************************
**************************************************************************************************
**** FIGURE OA.1
**************************************************************************************************
**************************************************************************************************

cd $data
u sampleA_extended.dta, clear

cd $figures
collapse cantwork_notemp_appl,by(months_to_int)

**** Figure OA1
gen s1=cantwork_notemp_appl if months_to_int<-2
gen s2=cantwork_notemp_appl if months_to_int>=-2
scatter s1 s2 months_to_int, s(oh dh) xtick(#24) xlabel(#24) ylabel(#10) ytick(#10) clp(dash dash) c(l l) lc(navy navy) mc(navy navy) ///
			xtitle("Interview Date - Application Date (Months)") ytitle("Fraction Disabled") xline(0,lp(solid)) graphr(c(white)) legend(off)
graph export "$figures\figureOA1.pdf", replace



cd $data
erase alt_disab_def.dta
erase ever_received_di_or_ssi.dta
erase primary_earner.dta
erase sampleA.dta
erase sampleA_labor_future.dta
erase sampleA_labor_past.dta
erase sampleA_extended.dta
erase sampleB.dta
erase sampleC.dta


**************************************************************************************************
log close
clear
 